﻿using System.Threading;
using RpcClient.Collect;
using RpcClient.Interface;
using RpcHelper;
using RpcModel;
using SocketTcpServer.FileUp;
using Wedonek.Demo.RemoteModel.Msg;
using Wedonek.Demo.RemoteModel.User;
using Wedonek.Demo.User.Service.Interface;

namespace Wedonek.Demo.User.Service
{
    internal class RpcEvent : IRpcEvent
    {
        public void RefreshService(long serverId)
        {
            //服务节点刷新事件
        }

        public void ServerClose()
        {
            //服务关闭事件
        }

        public void ServerStarted()
        {
            IRpcSagaTranService sage = RpcClient.RpcClient.Unity.Resolve<IRpcSagaTranService>();
            IRpcTccTranService tcc = RpcClient.RpcClient.Unity.Resolve<IRpcTccTranService>();
            tcc.RegTran<LockUserMoney, UserMoneyTccTran>();
           
            sage.RegTran<SetOrderNo>((a, b) =>
             {
                 IUserService user = RpcClient.RpcClient.Unity.Resolve<IUserService>();
                 user.SetOrderNo(a.UserId, a.OrderNo, b);
             });

            sage.RegTran<PlaceAnOrder>((a, b) =>
            {
                System.Console.WriteLine("PlaceAnOrder回滚了! ");
                System.Console.WriteLine(string.Concat("msg:", a.ToJson()));
            });
            FileUpRouteCollect.AddAllot(new Event.UpDemoFileEvent());
        }

        public void ServerStarting()
        {
            //服务启动前

        }

        public void ServiceState(RpcServiceState state)
        {
            //节点状态变更事件
        }
    }
}
